import request from '@/utils/request'
import axios from 'axios'
import { getToken as getAuthToken } from '@/utils/auth'

export function getList(data) {
  return request({
    url: '/word/find',
    method: 'get',
    params: { ...data }
  })
}

export function getRaList(id) {
  return request({
    url: '/word/ra/findByWid/' + id,
    method: 'get'
  })
}

export function getPhraseList(id) {
  return request({
    url: '/word/phrase/findByWid/' + id,
    method: 'get'
  })
}

export function getSimpleSentenceList(id) {
  return request({
    url: '/word/simpleSentence/findByWid/' + id,
    method: 'get'
  })
}

export function getFormList(id) {
  return request({
    url: '/word/form/findByWid/' + id,
    method: 'get'
  })
}

export function getPronounceList(id) {
  return request({
    url: '/word/pronounce/findByWid/' + id,
    method: 'get'
  })
}

export function getWord(id) {
  return request({
    url: '/word/findById/' + id,
    method: 'get'
  })
}

export function save(data) {
  return request({
    url: '/word/save',
    method: 'post',
    data
  })
}

export function update(data) {
  return request({
    url: '/word/update',
    method: 'put',
    data
  })
}

export function updateAllExSenPreNum() {
  return request({
    url: '/word/updateAllExSenPreNum',
    method: 'post'
  })
}

export function deleteMobile(id) {
  return request({
    url: '/word/del/' + id,
    method: 'delete'
  })
}

export function uploadBatch(data) {
  return request({
    url: '/word/uploadBatch',
    method: 'post',
    data
  })
}

export function getExSentence(word) {
  return request({
    url: '/subject/sentence/findByWord/' + word,
    method: 'get'
  })
}

export function downloadExcel(query) {
  const config = {
    params: query,
    responseType: 'blob',
    headers: {
      'Content-Type': 'application/json',
      'X-Token': getAuthToken(),
      'X-Access-Token': getAuthToken()
    }
  }
  return axios.get(process.env.VUE_APP_BASE_API + '/word/download', config)
}

export function baiduPull(id) {
  return request({
    url: '/word/pull/baidu/' + id,
    method: 'get'
  })
}

export function youdaoPull(id) {
  return request({
    url: '/word/pull/youdao/' + id,
    method: 'get'
  })
}

export function precisePull(data) {
  return request({
    url: '/word/precise',
    method: 'get',
    params: { ...data }
  })
}

